package sjtu.pirate.util;

import java.util.List;
/**
 * @author wilbur.ma@qq.com
 * @date 2011.05.31
 */
public class StringUtil {
	public static String join(String sep, List<String> tokens) {
		return join(sep, tokens.toArray(new String[0]));
	}
	
	public static String join(String sep, String... tokens) {
		String str = tokens[0];
		for (int i=1;i<tokens.length;i++)
			str += sep + tokens[i];
		return str;
	}
	
	public static String joinPath(String... tokens) {
		return join("/", tokens);
	}
	
	public static String trim(String str, String del) {
		int beginIndex = 0;
		int endIndex = str.length() - 1;
		for (char c : del.toCharArray()) {
			int begin = str.indexOf(c);
			int end = str.lastIndexOf(c);
			if (begin > beginIndex)
				beginIndex = begin;
			if (end != -1 && end < endIndex)
				endIndex = end;
		}
		return str.substring(beginIndex, endIndex);
	}
}
